﻿package utils;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;

public class FileReader {

	public static List<String> getListOfStringsFromTxt(String fileName) {

		List<String> listStrings = new LinkedList<String>();

		Scanner sc = null;

		try {
			sc = new Scanner(new BufferedReader(
					new java.io.FileReader(fileName)));

			while (sc.hasNextLine()) {
				listStrings.add(sc.nextLine());
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			if (sc != null) {
				sc.close();
			}
		}
		return listStrings;
	}

	public static List<String> getListOfStringsFromPDF(String fileName) {

		List<String> listStringsPDF = new LinkedList<String>();

		PDDocument docPDF;
		try {
			docPDF = PDDocument.load(fileName);

			PDFTextStripper stripperPDF = new PDFTextStripper();

			int numPages = docPDF.getNumberOfPages();

			for (int i = 1; i <= numPages; i++) {
				String text1 = stripperPDF.getText(docPDF);
				listStringsPDF.add(text1);
			}
			docPDF.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return listStringsPDF;
	}
}
